import { APP_FLIGHT_PATH, callService } from '@/common/common.js'


export function convertPriceInfo(prices, priceType, adultPrice) {
  for (let i = 0; i < prices.length; i++) {
    if (priceType === prices[i].priceType) {
      const priceInfo = prices[i]

      adultPrice.price = priceInfo.price
      adultPrice.parValue = priceInfo.parValue
      adultPrice.tax = priceInfo.tax
      adultPrice.insurance = 0
      adultPrice.serviceCharge = priceInfo.serviceCharge
      adultPrice.commission = priceInfo.commission
      adultPrice.commission2 = priceInfo.commission2
      adultPrice.discount = priceInfo.discount
      adultPrice.amount = priceInfo.amount
      adultPrice.cost = priceInfo.cost
      adultPrice.profit = priceInfo.profit
    }
  }
}

export function searchFlightOrders(params, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/order/flights'
  callService(url, {
    data: params,
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}

export function searchFlightOrdersToPrint(params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flights/print'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function searchFlightOrdersToDelivery(params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flights/delivery'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function searchFlightOrderDetail(id, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id
  callService(url, {
    cbDone: cbDone
  })
}

export function queryOrderRefundFee(id, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/refundFee'
  callService(url, {
    type: "get",
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}


export function queryFlightOrderChange(id, params, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/changeQuery'
  callService(url, {
    data: params,
    contentType: 'application/json',
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}

export function searchFlightOrderDetailByOrderNo(orderNo, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/orderNo/' + orderNo
  callService(url, {
    cbDone: cbDone
  })
}

export function searchFlightOrderHistory(id, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/history'
  callService(url, {
    cbDone: cbDone
  })
}

export function createFlightOrder(params, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/order/flight/new'
  callService(url, {
    contentType: 'application/json',
    data: params,
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}

export function createFlightOrderByPnr(params, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/order/flight/pnr'
  callService(url, {
    data: params,
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}

export function updateFlightOrderPrice(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/price'
  callService(url, {
    data: params,
    contentType: 'application/json',
    cbDone: cbDone
  })

}

export function updateFlightOrderPassenger(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/passenger'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function updateFlightOrderRemark(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/remark'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function updateFlightOrderPnr(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/pnr'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function updateFlightOrderKeyCustomerNo(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/keyCustomerNo'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function updateFlightOrderProperty(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/property'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function incFlightOrderPrintCount(id, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/print'
  callService(url, {
    cbDone: cbDone
  })
}

export function cancelFlightOrder(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/status/canceled'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function checkFlightOrderPrice(id, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/checkPrice'
  callService(url, {
    cbDone: cbDone
  })
}


export function searchCoupons(id, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/coupons'
  callService(url, {
    cbDone: cbDone
  })
}

export function confirmFlightOrderPrice(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/confirmPrice'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}



export function payForExternalOrder(id, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/pay'
  callService(url, {
    cbDone: cbDone
  })
}

export function issueFlightOrderTicket(id, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/issueTicket'
  callService(url, {
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}


export function cancelClaimFlightOrder(id, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/cancelClaim'
  callService(url, {
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}


export function submitFlightOrder(id, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/submit'
  callService(url, {
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}


export function approveFlightOrder(id, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/approved'
  callService(url, {
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}

export function toticketFlightOrder(id, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/toticket'
  callService(url, {
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}

export function finishFlightOrder(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/finish'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function gotFlightOrderNotice(id, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/noticeConfirmed'
  callService(url, {
    cbDone: cbDone
  })
}


export function outputFlightOrder2Bill(id, cbDone) {
  const url = APP_FLIGHT_PATH + '/convertFlightOrder2Bill'
  callService(url, {
    data: { id: id },
    cbDone: cbDone
  })
}

export function updateFlightOrderCustomer(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/customer'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function updateFlightOrderIntl(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/intlTicket'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function updateFlightOrderDeliveryDate(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/deliveryDate'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function updateFlightOrderTicketer(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/ticketer'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function updateFlightOrderSupplier(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/supplier'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}


export function changeFlightOrderSupplierType(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/supplierType'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function updateFlightOrderPaymentMethod(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/paymentMethod'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function updateFlightOrderTicket(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/ticket'
  callService(url, {
    data: params,
    contentType: 'application/json',
    cbDone: cbDone
  })
}

export function agreeFlightOrderCancelRequest(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/agreeCancelRequest'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function denyFlightOrderCancelRequest(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/denyCancelRequest'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

// 机票订单的行程单已邮寄
export function finishFlightOrderDelivery(id, params, cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/delivery/finished'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}


export function searchTpr(params, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/tprs'
  callService(url, {
    data: params,
    type: 'get',
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}

export function saveTprContent(params, cbDone) {
  const url = APP_FLIGHT_PATH + '/tpr/content'
  callService(url, {
    data: params,
    cbDone: cbDone
  })
}

export function statFlightOrderStatus(cbDone) {
  const url = APP_FLIGHT_PATH + '/order/flight/statStatus'
  callService(url, {
    cbDone: cbDone
  })
}

export function rav(params, done, fail, always) {
  const url = APP_FLIGHT_PATH + '/rav'
  callService(url, {
    timeout: 30000,
    data: params,
    cbDone: done,
    cbFail: fail,
    cbAlways: always
  })
}

export function searchOne(params, done, fail, always) {
  const url = APP_FLIGHT_PATH + '/searchOne'
  callService(url, {
    timeout: 10000,
    data: params,
    cbDone: done,
    cbFail: fail,
    cbAlways: always
  })
}


export function searchTgq(params, done, fail, always) {
  $.ajax({
    type: "post",
    url: '/Flight/flights/tgq',
    timeout: 3000,
    data: params,
    dataType: "json"
  }).done(function (jsonResult) {
    done(jsonResult)
  }).fail(function (jqXHR, textStatus, errorThrown) {
    // fail(jqXHR.status, jqXHR.statusText)
  }).always(function () {
    // always()
  })
}

export function searchStopover(params, done, fail, always) {
  const url = APP_FLIGHT_PATH + '/flight/stopover'
  callService(url, {
    type: 'get',
    timeout: 10000,
    data: params,
    cbDone: done,
    cbFail: fail,
    cbAlways: always
  })
}


// 上传机票订单乘机人信息
export function uploadFlightOrderPassengers(id, params, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/passengers/upload'
  console.log(url)
  callService(url, {
    data: params,
    contentType: false,
    cache: false,
    processData: false,
    timeout: 0,
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}

export function createEotmsFlightOrder(id, params, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/externalOrder'
  callService(url, {
    data: params,
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}

export function searchEotmsFlightOrders(id, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/externalOrders'
  callService(url, {
    type: 'get',
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}

export function syncEotmsFlightOrderStatus(id, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/order/flight/external/' + id
  callService(url, {
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}

export function confirmEotmsFlightOrder(id, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/order/flight/external/' + id + '/confirm'
  callService(url, {
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}


export function searchTmsSuppliers(cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/tmsSuppliers'
  callService(url, {
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}


export function syncFlightOrderExternalOrderStatus(id, cbDone, cbAlways) {
  const url = APP_FLIGHT_PATH + '/order/flight/' + id + '/syncStatus'
  callService(url, {
    cbDone: cbDone,
    cbAlways: cbAlways
  })
}